import 'package:flutter/material.dart';
import 'package:flutter_learn_demo/localreferesh/textwidget.dart';

class LocalRefreshTest extends StatefulWidget {

  const LocalRefreshTest({super.key});

  @override
  State<StatefulWidget> createState() => LocalRefreshTestState();
}

class LocalRefreshTestState extends State<LocalRefreshTest> {

  int count = 0;

  GlobalKey<TextWidgetState> gKey = GlobalKey<TextWidgetState>();

  @override
  Widget build(BuildContext context) {
      print('BuildContext context');
      return Scaffold(
        appBar: AppBar(
          title: const Text('LocalRefresh'),
          backgroundColor: Colors.deepPurple,
        ),
        body: Container(
          alignment: Alignment.center,
          child: Column(
            children: [
              TextWidget(mKey: gKey),
              ElevatedButton(onPressed: (){
                count++;
                gKey.currentState!.onPressed(count);
              }, child: const Text('增加值',style: TextStyle(color: Colors.deepPurple,fontSize: 20),)),
            ],
          ),
        ),
      );
  }

}